import React from "react";
import Son from "./son";
class App extends React.Component {
  constructor(props) {
    console.log("constructor");
    super(props);
    this.state = {
      name: "father",
    };
  }

  static getDerivedStateFromProps(props, state) {
    console.log("getDerivedStateFromProps");
    return null;
  }
  shouldComponentUpdate(props, state) {
    console.log("shouldComponentUpdate");
    // 优化生成周期
    let ifChange = true;
    for (let item in this.state) {
      if (this.state[item] !== state[item]) {
        ifChange = false;
      }
    }
    return ifChange;
  }
  render() {
    console.log("render");
    return (
      <div>
        {this.state.name}
        <Son></Son>
        <button onClick={() => this.setState({ name: "father" })}>改变</button>
      </div>
    );
  }
  componentDidMount() {
    console.log("componentDidMount");
  }
  componentDidUpdate() {
    console.log("componentDidUpdate");
  }
}
export default App;
